/*
 * Do not forget to test your class!!!
 *
 * Be sure to test ALL methods and all different cases of
 * the methods (the only exception allowed is overallLetterGrade)
 * For example, in addition to checking to be sure all normal cases
 * working correctly, be sure to test exception cases in 
 * addHomework so that method will not create an indexOutOfBounds
 * error.  Be sure your changeHomework method does not change the
 * homework grade if n is past where you have already entered.  Check
 * to make sure your getHomeworkGrade will return -1 if n is past
 * where have already entered.
 * Do not forget to avoid integer division when calculating averages!
 * Be sure at least 1 of your averages has a decimal!
 *
 * Remember to calculate expected results!
 * Display Expected = '  '  then calculate your answer and display
 * your answer to be sure it matches!
 */

public class JavaGradeArray {
	/*
	 * Constructor initializes Array to hold up to 10 homework and test grades.
	 */
	public JavaGradeArray() {
		test = new int[10];
		homework = new int[10];
		testCount = 0;
		homeworkCount = 0;
	}

	/*
	 * Adds a homework grade to the array. If there is no more room in the array
	 * do not add the grade to the array. Return true if the grade is
	 * successfully added, return false if the grade is not added.
	 */
	public boolean addHomework(int newHomeworkGrade) {
		if (homeworkCount <= test.length) {
			homework[homeworkCount++] = newHomeworkGrade;
			return true;
		}
		return false;
	}

	/*
	 * Changes a grade of an already entered homework. Recall n is the number of
	 * the homework - begins at 1! If the number of the homework has not yet
	 * been entered do not change the grade. Do not allow an indexOutOfBounds
	 * erorr. If n is too small or too big, do not change the grade. Return true
	 * if the grade is successfully added, return false if the grade is not
	 * added.
	 */
	public boolean changeHomework(int changeHomeworkGrade, int n) {
		if (n >= 1 && n <= homeworkCount) {
			homework[n - 1] = changeHomeworkGrade;
			return true;
		}
		return false;
	}

	/*
	 * Computes the homework average of only the entered homework grades
	 */
	public double homeworkAverage() {
		double sum = 0;
		for(double d:homework)
		{
			sum+=d;
		}
		return sum/homeworkCount;
	}

	/*
	 * Returns the grade of the nth homework. Recall where the first homework is
	 * stored in the array! If the grade at the nth position has not yet been
	 * entered, return -1. Do not allow an indexOutOfBounds erorr. If n is too
	 * small or too big, do not change the grade and return -1.
	 */
	public int getHomeworkGrade(int n) {
		if (n-1 >= 0 && n <= homeworkCount)
			return homework[n-1];
		return -1;
	}

	/*
	 * All test methods work the same way as homework methods. Copy, paste and
	 * adjust where needed!
	 */
	public boolean addTest(int newTestGrade) {
		if (testCount <= test.length) {
			test[testCount++] = newTestGrade;
			return true;
		}
		return false;
	}

	public double testAverage() {
		double sum = 0;
		for(double d:test)
		{
			sum+=d;
		}
		return sum/testCount;
	}

	public boolean changeTest(int changeTestGrade, int n) {
		if (n >= 1 && n <= testCount) {
			test[n - 1] = changeTestGrade;
			return true;
		}
		return false;
	}

	public int getTestGrade(int n) {
		if (n-1 >= 0 && n <= testCount)
			return test[n-1];
		return -1;
	}

	/*
	 * Returns the weighted average of 25% homework, 75% tests, Make use of
	 * other methods! Do not repeat code!
	 */
	public double overallGrade() {
		return testAverage()*.75+homeworkAverage()*.25;
	}

	/*
	 * Returns a String of your overall letter grade of A, B, C, D or F based on
	 * the Neuqua grading scale. Again, Do NOT repeat code!
	 */
	public String overallLetterGrade() {
		double numGrade = overallGrade();
			//Put your code here
			if(numGrade>=100)
				return "A+";
			if(numGrade>=91)
				return "A";
			if(numGrade>=81)
				return "B";
			if(numGrade>=71)
				return "C";
			if(numGrade>=65)
				return "D";
			if(numGrade>=0)
				return "F";
			return("You did real bad.");
	}

	/*
	 * Returns a String of your overall letter grade of A, B, C, D or F based on
	 * the Neuqua grading scale. Example format: JavaGrade = A Example format 2:
	 * JavaGrade = C
	 */
	public String toString() {
		return "JavaGrade = "+overallLetterGrade();
	}

	/*
	 * Returns true if n is in range of the Homework or Test array, otherwise
	 * returns false hOrT false = Homework array hOrT true = Test array Note:
	 * This method is private and cannot be tested outside of the class.
	 */
	private boolean isInRange(int n, boolean hOrT) {
		return n >= 1 && n <= (hOrT?homeworkCount:testCount);
	}

	// Do NOT modify instance fields! You cannot change the design of this code!
	private int[] homework;
	private int homeworkCount;
	private int[] test;
	private int testCount;
}
